<?php
//Have to be declared before I do any xhtml outputs. (aka have to be send with the headers)
session_start();

ini_set('display_errors', 1); 
//ini_set('log_errors', 1); 
//ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); 
error_reporting(E_ALL);

//require_one includes documents so that they're accessible throughout all documents in the project.
require_once ("view/FileUploadView.php");
require_once ("view/LogView.php");
require_once ("view/LoginView.php");
require_once ("view/MakeNewPostView.php");
require_once ("view/MemberView.php");
require_once ("view/NavigationView.php");
require_once ("view/ObserverView.php");
require_once ("view/PageCompositionView.php");
require_once ("view/PageView.php");

require_once ("model/FileUploadHandler.php");
require_once ("model/LoginHandler.php");
require_once ("model/Member.php");
require_once ("model/memberDAL.php");
require_once ("model/MemberHandler.php");
require_once ("model/ObserverDAL.php");
require_once ("model/ObserverHandler.php");
require_once ("model/Post.php");

require_once ("controller/DeleteMemberController.php");
require_once ("controller/FileUploadController.php");
require_once ("controller/LoginController.php");
require_once ("controller/LogoutController.php");
require_once ("controller/MakeNewPostController.php");
require_once ("controller/MasterController.php");
require_once ("controller/MemberController.php");
require_once ("controller/ObserverController.php");
require_once ("controller/UpdatePostController.php");

require_once ("common/config.php");
require_once ("common/DBConnection.php");
require_once ("common/Log.php");
require_once ("common/settings.php");
require_once ("common/Validate.php");

//Create new connection to the database
$dbConnection = new DBConnection();
//Connect to database
$dbConnection->Connect();

$validate = new Validate();

$fileUploadView = new FileUploadView();
$loginView = new LoginView();
$makeNewPostView = new MakeNewPostView();
$memberView = new MemberView($validate);
$navigationView = new NavigationView();
$observerView = new ObserverView();

$memberDAL = new memberDAL($dbConnection);
$observerDAL = new ObserverDAL($dbConnection);

$fileUploadHandler = new FileuploadHandler();
$loginHandler = new LoginHandler($memberDAL);
$memberHandler = new MemberHandler($dbConnection, $memberDAL);
$observerHandler = new ObserverHandler($dbConnection, $observerDAL);

$memberController = new MemberController($loginHandler,
										$loginView, 	
										$memberHandler, 
										$memberView,
										$memberDAL);
										
$loginController = new LoginController($loginHandler, 
										$memberView,
										$loginView);
										
$observerController = new ObserverController($observerHandler, 
											$observerView,
											$loginHandler);	
											
$logoutController = new LogoutController($loginHandler, 
										$loginView);

$deleteMemberController = new DeleteMemberController ($memberView, 
													$memberDAL, 
													$loginView,
													$loginHandler);	

$makeNewPostController = new MakeNewPostController($makeNewPostView, 
													$observerController, 
													$observerHandler, 
													$validate,
													$navigationView);		

$updatePostController = new UpdatePostController($observerView, 
												$observerHandler, 
												$navigationView, 
												$fileUploadView, 
												$validate, 
												$fileUploadHandler);	

$fileUploadController = new FileUploadController ();																		

$masterController = new MasterController($dbConnection, 
										$navigationView, 
										$memberController,
										$loginController,
										$observerController,
										$logoutController,
										$makeNewPostController,
										$deleteMemberController,
										$updatePostController,
										$fileUploadController);

$pageView = new PageView ();

//set page title
$title = "StudentKalmar";

//xhtml that will show in body
$xhtml = "";

//save xhtml from mastercontroller in variable $xhtml
$xhtml .= $masterController ->DoControl();

//Link stylesheet
$pageView -> AddStyleSheet("css/reset.css");
$pageView -> AddStyleSheet("css/regular.css");
$pageView -> AddStyleSheet("css/text.css");

//Writes Xhtml for body and head.
echo $pageView -> GetXHTML10StrictPage($title, $xhtml);
//Don't have ? > if you accidentally have a space or tab after the end sign it will print on clientside. 
